package com.cwd.arm.inter.util;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.cwd.arm.application.dto.ConfirmIncomeDto;
import com.cwd.arm.application.dto.board.RtDto;
import com.cwd.arm.application.dto.confirmIncome.ConfirmIncomeAddDto;
import com.cwd.arm.application.dto.confirmIncome.ConfirmIncomeUpdateDto;
import com.cwd.arm.application.dto.confirmIncome.TargetConfirmAmountAddDto;
import com.cwd.arm.application.dto.confirmIncome.TargetConfirmAmountUpdateDto;
import com.cwd.arm.application.dto.pay.PayAddDto;
import com.cwd.arm.application.dto.pay.PayUpdateDto;
import com.cwd.arm.application.dto.project.ProjectAddDto;
import com.cwd.arm.application.dto.project.ProjectUpdateDto;
import com.cwd.arm.application.dto.receiveNode.ReceiveNodeAddDto;
import com.cwd.arm.application.dto.receiveNode.ReceiveNodeUpdateDto;
import com.cwd.arm.application.dto.receiveRecord.ReceiveRecordAddDto;
import com.cwd.arm.application.dto.receiveRecord.ReceiveRecordUpdateDto;
import com.cwd.arm.application.dto.role.RoleAddDto;
import com.cwd.arm.application.dto.role.RoleUpdateDto;
import com.cwd.arm.application.dto.tax.TaxAddDto;
import com.cwd.arm.application.dto.tax.TaxUpdateDto;
import com.cwd.arm.application.dto.user.UserAddDto;
import com.cwd.arm.application.dto.user.UserUpdateDto;
import com.cwd.arm.common.dto.session.AuthDto;
import com.cwd.arm.inter.vo.auth.AuthVo;
import com.cwd.arm.inter.vo.board.RtVo;
import com.cwd.arm.inter.vo.confirmIncome.ConfirmIncomeAddVo;
import com.cwd.arm.inter.vo.confirmIncome.ConfirmIncomeUpdateVo;
import com.cwd.arm.inter.vo.confirmIncome.ConfirmIncomeVo;
import com.cwd.arm.inter.vo.confirmIncome.TargetConfirmAmountUpdateVo;
import com.cwd.arm.inter.vo.pay.PayAddVo;
import com.cwd.arm.inter.vo.pay.PayUpdateVo;
import com.cwd.arm.inter.vo.project.ProjectAddVo;
import com.cwd.arm.inter.vo.project.ProjectUpdateVo;
import com.cwd.arm.inter.vo.receivableAmountVo.ReceivePlanUpdateVo;
import com.cwd.arm.inter.vo.receiveNode.ReceiveNodeAddVo;
import com.cwd.arm.inter.vo.receiveNode.ReceiveNodeUpdateVo;
import com.cwd.arm.inter.vo.receiveRecord.ReceiveRecordAddVo;
import com.cwd.arm.inter.vo.receiveRecord.ReceiveRecordUpdateVo;
import com.cwd.arm.inter.vo.role.RoleAddVo;
import com.cwd.arm.inter.vo.role.RoleUpdateVo;
import com.cwd.arm.inter.vo.tax.TaxAddVo;
import com.cwd.arm.inter.vo.tax.TaxUpdateVo;
import com.cwd.arm.inter.vo.user.UserAddVo;
import com.cwd.arm.inter.vo.user.UserResetPasswordVo;
import com.cwd.arm.inter.vo.user.UserUpdateVo;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by yan on 21-12-4.
 */
public class VoToDtoUtil {

    public static ProjectAddDto convertToDto(ProjectAddVo vo) {
        ProjectAddDto dto = new ProjectAddDto();
        BeanUtils.copyProperties(vo, dto);
        if (CollectionUtils.isNotEmpty(vo.getReceiveNodeAddVoList())) {
            dto.setReceiveNodeAddList(convertToReceiveNodeAddDtoList(vo.getReceiveNodeAddVoList()));
        }
        dto.setReceiveDirectorIdList(vo.getReceiveDirectorIdList());
        return dto;
    }

    public static ProjectUpdateDto convertToDto(ProjectUpdateVo vo) {
        ProjectUpdateDto dto = new ProjectUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        dto.setReceiveDirectorIdList(vo.getReceiveDirectorIdList());
        return dto;
    }

    public static ReceiveNodeAddDto convertToDto(ReceiveNodeAddVo vo) {
        ReceiveNodeAddDto dto = new ReceiveNodeAddDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static List<ReceiveNodeAddDto> convertToReceiveNodeAddDtoList(List<ReceiveNodeAddVo> voList) {
        return voList.stream().map(vo -> (convertToDto(vo))).collect(Collectors.toList());
    }

    public static ReceiveNodeUpdateDto convertToDto(ReceiveNodeUpdateVo vo) {
        ReceiveNodeUpdateDto dto = new ReceiveNodeUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static TaxAddDto convertToDto(TaxAddVo vo) {
        TaxAddDto dto = new TaxAddDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static TaxUpdateDto convertToDto(TaxUpdateVo vo) {
        TaxUpdateDto dto = new TaxUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static ReceiveRecordAddDto convertToDto(ReceiveRecordAddVo vo) {
        ReceiveRecordAddDto dto = new ReceiveRecordAddDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static ReceiveRecordUpdateDto convertToDto(ReceiveRecordUpdateVo vo) {
        ReceiveRecordUpdateDto dto = new ReceiveRecordUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static ConfirmIncomeVo convertToVo(ConfirmIncomeDto dto) {
        ConfirmIncomeVo vo = new ConfirmIncomeVo();
        BeanUtils.copyProperties(dto, vo);
        return vo;
    }

    public static ConfirmIncomeAddDto convertToDto(ConfirmIncomeAddVo vo) {
        ConfirmIncomeAddDto dto = new ConfirmIncomeAddDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static ConfirmIncomeUpdateDto convertToDto(ConfirmIncomeUpdateVo vo) {
        ConfirmIncomeUpdateDto dto = new ConfirmIncomeUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static TargetConfirmAmountUpdateDto convertToDto(TargetConfirmAmountUpdateVo vo) {
        TargetConfirmAmountUpdateDto dto = new TargetConfirmAmountUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static PayAddDto convertToDto(PayAddVo vo) {
        PayAddDto dto = new PayAddDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static PayUpdateDto convertToDto(PayUpdateVo vo) {
        PayUpdateDto dto = new PayUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static UserAddDto convertToDto(UserAddVo vo) {
        UserAddDto dto = new UserAddDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static UserUpdateDto convertToDto(UserUpdateVo vo) {
        UserUpdateDto dto = new UserUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static UserUpdateDto convertToDto(UserResetPasswordVo vo) {
        UserUpdateDto dto = new UserUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }


    public static RoleAddDto convertToDto(RoleAddVo vo) {
        RoleAddDto dto = new RoleAddDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static RoleUpdateDto convertToDto(RoleUpdateVo vo) {
        RoleUpdateDto dto = new RoleUpdateDto();
        BeanUtils.copyProperties(vo, dto);
        if (CollectionUtils.isNotEmpty(vo.getBtnAuthList())) {
            dto.setBtnAuthList(convertToAuthDtoList(vo.getBtnAuthList()));
        }
        if(CollectionUtils.isNotEmpty(vo.getMenuAuthList())){
            dto.setMenuAuthList(convertToAuthDtoList(vo.getMenuAuthList()));
        }
        return dto;
    }

    private static List<AuthDto> convertToAuthDtoList(List<AuthVo> authVoList){
       return authVoList.stream().map(vo->(convertToDto(vo))).collect(Collectors.toList());
    }

    public static AuthDto convertToDto(AuthVo vo) {
        AuthDto dto = new AuthDto();
        BeanUtils.copyProperties(vo, dto);
        return dto;
    }

    public static ProjectUpdateDto convertToDto(ReceivePlanUpdateVo vo) {
        ProjectUpdateDto dto = new ProjectUpdateDto();
        dto.setId(vo.getProjectId());
        dto.setRemark(vo.getRemark());
        return dto;
    }

}
